﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WSIMWindowsClient.WSIMGeneral;
using WSIMWindowsClient.WSIMMessaging;
using WSIMWindowsClient.WSIMProfile;

namespace WSIMWindowsClient
{
    class ObjectFactory
    {

        private static WSIMGeneral.WSIMGeneralOperationsClient ws1 = new WSIMWindowsClient.WSIMGeneral.WSIMGeneralOperationsClient();
        private static WSIMMessaging.WSIMMessagingOperationsClient ws2 = new WSIMWindowsClient.WSIMMessaging.WSIMMessagingOperationsClient();
        private static WSIMProfile.WSIMProfileOperationsClient ws3 = new WSIMWindowsClient.WSIMProfile.WSIMProfileOperationsClient();

        static ObjectFactory(){
            UpdateCredentials(global::WSIMWindowsClient.Properties.Settings.Default.wsimUsername,
                global::WSIMWindowsClient.Properties.Settings.Default.wsimPassword);
        }

        public static void UpdateCredentials(string username, string password) {
            ws2.ClientCredentials.UserName.UserName = username;
            ws2.ClientCredentials.UserName.Password = password;
            ws1.ClientCredentials.UserName.UserName = username;
            ws1.ClientCredentials.UserName.Password = password;
            ws3.ClientCredentials.UserName.UserName = username;
            ws3.ClientCredentials.UserName.Password = password;
            
        }


        public static WSIMProfileOperationsClient GetProfileWS() {
            return ws3;
        }


        public static WSIMMessagingOperationsClient GetMessagingWS(bool recreate)
        {
            if (recreate) {
                ws2 = new WSIMMessagingOperationsClient();
                UpdateCredentials(global::WSIMWindowsClient.Properties.Settings.Default.wsimUsername,
                global::WSIMWindowsClient.Properties.Settings.Default.wsimPassword);
            }
            return ws2;
        }

        public static WSIMGeneralOperationsClient GetGeneralWS()
        {
            return ws1;
        }

    }
}
